;(function() {
	Nokia.Template = new Nokia.Class({
		container: null,
		header: null, // nokia-template-header
		content: null, // nokia-template-content
		footer: null, //nokia-template-footer

		initialize: function(options) {
			var instance = this;

			instance.options = options;

			instance.setContainer(
				Nokia.dom.parseHTML('<div class="nokia-template-container"></div>')
			);

			Nokia.dom.append(document.body, instance.getContainer());

			// Timer to check if in landscape mode

			instance.lastInLandscapeMode = null;

			setInterval(function() {

				if (options && options.viewManager) {

					var viewManager = options.viewManager,
						newInLandscapeMode = viewManager.inLandscapeMode();

					// Prevents unnecessary dom manipulation
					if (instance.lastInLandscapeMode != newInLandscapeMode) {
						instance.lastInLandscapeMode = newInLandscapeMode;

						if (newInLandscapeMode) {
							instance.onLandscapeEnabled();
						} else {
							instance.onLandscapeDisabled();
						}

					}

				}

			}, 1000);
		},

		setContainer: function(container) {
			var instance = this;

			instance.container = Nokia.dom.parseHTML(container);
		},

		setHeader: function(header) {
			var instance = this;

			instance.header = Nokia.dom.parseHTML(header);
		},

		setContent: function(content) {
			var instance = this;

			instance.content = Nokia.dom.parseHTML(content);
		},

		setFooter: function(footer) {
			var instance = this;

			instance.footer = Nokia.dom.parseHTML(footer);
		},

		getContainer: function() {
			var instance = this;

			return instance.container;
		},

		getHeader: function() {
			var instance = this;

			return instance.header;
		},

		getContent: function() {
			var instance = this;

			return instance.content;
		},

		getFooter: function() {
			var instance = this;

			return instance.footer;
		},

		// listener
		onLandscapeEnabled: function() {
			var instance = this,
				header = instance.getHeader(),
				content = instance.getContent(),
				footer = instance.getFooter();

			if (header) {
				header.addClass('nokia-template-header-landscape');
			}

			if (content) {
				content.addClass('nokia-template-content-landscape');
			}

			if (footer) {
				footer.addClass('nokia-template-footer-landscape');
			}

		},

		// listener
		onLandscapeDisabled: function() {
			var instance = this,
				header = instance.getHeader(),
				content = instance.getContent(),
				footer = instance.getFooter();

			if (header) {
				header.removeClass('nokia-template-header-landscape');
			}

			if (content) {
				content.removeClass('nokia-template-content-landscape');
			}

			if (footer) {
				footer.removeClass('nokia-template-footer-landscape');
			}

		}
	});
})();